package com.guoheng.hazard.sys.service.impl.entpr;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.sys.mapper.entpr.EntprMaterialProductMapper;
import com.guoheng.hazard.sys.model.dto.entpr.EntprMaterialProductInsertDTO;
import com.guoheng.hazard.sys.model.dto.entpr.EntprMaterialProductUpdateDTO;
import com.guoheng.hazard.sys.model.entity.entpr.EntprMaterialProduct;
import com.guoheng.hazard.sys.service.entpr.EntprMaterialProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 类功能描述:　企业生产信息
 *
 * @author fbl
 * @date 2019-11-12 10:33
 */
@Service
public class EntprMaterialProductServiceImpl implements EntprMaterialProductService {

    @Resource
    EntprMaterialProductMapper entprMaterialProductMapper;

    @Override
    public Result getEntprProducts(Long entprId, Integer pageNum, Integer pageSize, Integer productType) {
        PageHelper.startPage(pageNum, pageSize);
        List<EntprMaterialProduct> entprProducts = entprMaterialProductMapper.getEntprProducts(entprId, productType);
        PageInfo<EntprMaterialProduct> entprMaterialProductPageInfo = new PageInfo<>(entprProducts);
        return Result.success(entprMaterialProductPageInfo);
    }

    @Override
    public Result updateEntprProducts(EntprMaterialProductUpdateDTO entprMaterialProductUpdateDTO) {
        EntprMaterialProduct entprMaterialProduct = new EntprMaterialProduct();
        BeanUtils.copyProperties(entprMaterialProductUpdateDTO, entprMaterialProduct);
        entprMaterialProductMapper.updateEntprProducts(entprMaterialProduct);
        return Result.success();
    }

    @Override
    public Result insertEntprProducts(EntprMaterialProductInsertDTO entprMaterialProductInsertDTO) {
        EntprMaterialProduct entprMaterialProduct = new EntprMaterialProduct();
        BeanUtils.copyProperties(entprMaterialProductInsertDTO, entprMaterialProduct);
        entprMaterialProductMapper.insertEntprProducts(entprMaterialProduct);
        return Result.success();
    }

    @Override
    public Result selectEntprProductById(Long id) {
        EntprMaterialProduct entprMaterialProduct = entprMaterialProductMapper.selectEntprProductById(id);
        return Result.success(entprMaterialProduct);
    }

    @Override
    public Result deleteEntprProduct(Long id) {
        EntprMaterialProduct entprMaterialProduct = new EntprMaterialProduct();
        entprMaterialProduct.setId(id);
        entprMaterialProduct.setDelFlag(true);
        entprMaterialProductMapper.updateEntprProducts(entprMaterialProduct);
        return Result.success();
    }
}